import { S } from '../s';
import { IPSAppDataEntity } from '../app/dataentity/ipsapp-data-entity';
import { IPSControl } from './ipscontrol';
import { IPSControlAction } from './ipscontrol-action';
import { IPSControlAttribute } from './ipscontrol-attribute';
import { IPSControlHandler } from './ipscontrol-handler';
import { IPSControlLogic } from './ipscontrol-logic';
import { IPSControlParam } from './ipscontrol-param';
import { IPSControlRender } from './ipscontrol-render';
import { IPSCtrlMsg } from '../res/ipsctrl-msg';
import { IPSSysCss } from '../res/ipssys-css';
import { IPSSysPFPlugin } from '../res/ipssys-pfplugin';
import { PSModelObjectImpl } from '../psmodel-object-impl';

export class PSControlImpl extends PSModelObjectImpl implements IPSControl {
  get codeName(): string {
    return this.M.codeName;
  }

  get controlStyle(): string {
    return this.M.controlStyle;
  }

  get controlType():
    | 'TOOLBAR'
    | 'GRID'
    | 'FORM'
    | 'SEARCHFORM'
    | 'DRBAR'
    | 'VIEWPANEL'
    | 'PICKUPVIEWPANEL'
    | 'DATAVIEW'
    | 'TREEGRID'
    | 'WFEXPBAR'
    | 'TREEVIEW'
    | 'TREEEXPBAR'
    | 'TABVIEWPANEL'
    | 'DRTAB'
    | 'CHART'
    | 'REPORTPANEL'
    | 'LIST'
    | 'MOBMDCTRL'
    | 'MULTIEDITVIEWPANEL'
    | 'WIZARDPANEL'
    | 'UPDATEPANEL'
    | 'SEARCHBAR'
    | 'DASHBOARD'
    | 'CALENDAR'
    | 'PANEL'
    | 'MAP'
    | 'GANTT'
    | 'TREEGRIDEX'
    | 'KANBAN'
    | 'CALENDAREXPBAR'
    | 'CHARTEXPBAR'
    | 'DATAVIEWEXPBAR'
    | 'GANTTEXPBAR'
    | 'GRIDEXPBAR'
    | 'LISTEXPBAR'
    | 'MAPEXPBAR'
    | 'STATEWIZARDPANEL'
    | 'APPMENU'
    | 'TABEXPPANEL'
    | 'CUSTOM' {
    return this.M.controlType;
  }

  get dynaModelFilePath(): string {
    return this.M.dynaModelFilePath;
  }

  get height(): number {
    return this.M.height != null ? this.M.height : 0.0;
  }

  protected hookeventnames: string[];
  getHookEventNames(): string[] | null {
    if (this.hookeventnames == null) {
      const value = this.M.hookEventNames;
      if (value == null) {
        return null;
      }
      const arrayNode: any[] = value;
      if (arrayNode.length == 0) {
        return null;
      }
      const list: string[] = [];
      for (let i = 0; i < arrayNode.length; i++) {
        list.push(arrayNode[i]);
      }
      this.hookeventnames = list;
    }
    return this.hookeventnames.length == 0 ? null : this.hookeventnames;
  }

  get logicName(): string {
    return this.M.logicName;
  }

  protected psappdataentity: IPSAppDataEntity;
  getPSAppDataEntity(): IPSAppDataEntity | null {
    return (
      this.psappdataentity ||
      (this.psappdataentity = this.fillObjectModel(
        S._f,
        this.M.getPSAppDataEntity,
        S._2aa,
      ) as IPSAppDataEntity)
    );
  }

  protected pscontrolattributes: IPSControlAttribute[];
  getPSControlAttributes(): IPSControlAttribute[] | null {
    return (
      this.pscontrolattributes ||
      (this.pscontrolattributes = this.fillChildListModel(
        this.M.getPSControlAttributes,
        S._3f5,
      ) as IPSControlAttribute[])
    );
  }

  findPSControlAttribute(objKey: any): IPSControlAttribute | null {
    return this.getPSModel5(
      S._3f5,
      this.getPSControlAttributes(),
      objKey,
    ) as IPSControlAttribute;
  }

  protected pscontrolhandler: IPSControlHandler;
  getPSControlHandler(): IPSControlHandler | null {
    return (
      this.pscontrolhandler ||
      (this.pscontrolhandler = this.fillObjectModel(
        S._95,
        this.M.getPSControlHandler,
        S._335,
      ) as IPSControlHandler)
    );
  }

  protected pscontrollogics: IPSControlLogic[];
  getPSControlLogics(): IPSControlLogic[] | null {
    return (
      this.pscontrollogics ||
      (this.pscontrollogics = this.fillChildListModel(
        this.M.getPSControlLogics,
        S._38d,
      ) as IPSControlLogic[])
    );
  }

  findPSControlLogic(objKey: any): IPSControlLogic | null {
    return this.getPSModel5(
      S._38d,
      this.getPSControlLogics(),
      objKey,
    ) as IPSControlLogic;
  }

  protected pscontrolparam: IPSControlParam;
  getPSControlParam(): IPSControlParam | null {
    return (
      this.pscontrolparam ||
      (this.pscontrolparam = this.fillObjectModel(
        S._127,
        this.M.getPSControlParam,
        S._336,
      ) as IPSControlParam)
    );
  }

  protected pscontrolrenders: IPSControlRender[];
  getPSControlRenders(): IPSControlRender[] | null {
    return (
      this.pscontrolrenders ||
      (this.pscontrolrenders = this.fillChildListModel(
        this.M.getPSControlRenders,
        S._3f6,
      ) as IPSControlRender[])
    );
  }

  findPSControlRender(objKey: any): IPSControlRender | null {
    return this.getPSModel5(
      S._3f6,
      this.getPSControlRenders(),
      objKey,
    ) as IPSControlRender;
  }

  protected psctrlmsg: IPSCtrlMsg;
  getPSCtrlMsg(): IPSCtrlMsg | null {
    return (
      this.psctrlmsg ||
      (this.psctrlmsg = this.fillObjectModel(
        S._275,
        this.M.getPSCtrlMsg,
        S._3f3,
      ) as IPSCtrlMsg)
    );
  }

  protected pssyscss: IPSSysCss;
  getPSSysCss(): IPSSysCss | null {
    return (
      this.pssyscss ||
      (this.pssyscss = this.fillObjectModel(
        S._278,
        this.M.getPSSysCss,
        S._2ac,
      ) as IPSSysCss)
    );
  }

  protected pssyspfplugin: IPSSysPFPlugin;
  getPSSysPFPlugin(): IPSSysPFPlugin | null {
    return (
      this.pssyspfplugin ||
      (this.pssyspfplugin = this.fillObjectModel(
        S._27c,
        this.M.getPSSysPFPlugin,
        S._2a7,
      ) as IPSSysPFPlugin)
    );
  }

  protected user2pscontrolaction: IPSControlAction;
  getUser2PSControlAction(): IPSControlAction | null {
    if (this.user2pscontrolaction != null) return this.user2pscontrolaction;
    const value = this.M.getUser2PSControlAction;
    if (value == null) {
      return;
    }
    this.user2pscontrolaction =
      this.getPSControlHandler().findPSControlHandlerAction(value);
    return this.user2pscontrolaction;
  }

  protected userpscontrolaction: IPSControlAction;
  getUserPSControlAction(): IPSControlAction | null {
    if (this.userpscontrolaction != null) return this.userpscontrolaction;
    const value = this.M.getUserPSControlAction;
    if (value == null) {
      return;
    }
    this.userpscontrolaction =
      this.getPSControlHandler().findPSControlHandlerAction(value);
    return this.userpscontrolaction;
  }

  get userTag(): string {
    return this.M.userTag;
  }

  get userTag2(): string {
    return this.M.userTag2;
  }

  get width(): number {
    return this.M.width != null ? this.M.width : 0.0;
  }
  get cls(): string {
    return 'PSControlImpl';
  }
  instanceof(cls: string): boolean {
    if (cls == S._214) return true;
    return super.instanceof(cls);
  }
}
